package com.dime.basic.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.dime.basic.api.domain.DimeBasecomb;
import com.dime.basic.api.model.Combo;
import com.dime.basic.api.model.ComboBase;
import com.dime.basic.api.model.DimeBasicDataResult;
import com.dime.basic.api.model.HarmCombo;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.security.annotation.InnerAuth;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;

import com.dime.basic.service.IDimeBasecombService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 项目组合管理Controller
 *
 * @author Tiny
 * @date 2023-09-13
 */
@RestController
@RequestMapping("/basecomb")
public class DimeBasecombController extends BaseController
{
    @Autowired
    private IDimeBasecombService dimeBasecombService;

    /**
     * 查询项目组合管理列表
     */
   // @RequiresPermissions("basic:basecomb:list")
    @GetMapping("/list")
    public TableDataInfo list(DimeBasecomb dimeBasecomb)
    {
        startPage();
        List<DimeBasecomb> list = dimeBasecombService.selectDimeBasecombList(dimeBasecomb);
        return getDataTable(list);
    }

    /**
     * 导出项目组合管理列表
     */
    @RequiresPermissions("basic:basecomb:export")
    @Log(title = "项目组合管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DimeBasecomb dimeBasecomb)
    {
        List<DimeBasecomb> list = dimeBasecombService.selectDimeBasecombList(dimeBasecomb);
        ExcelUtil<DimeBasecomb> util = new ExcelUtil<DimeBasecomb>(DimeBasecomb.class);
        util.exportExcel(response, list, "项目组合管理数据");
    }

    /**
     * 获取项目组合管理详细信息
     */
    @RequiresPermissions("basic:basecomb:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(dimeBasecombService.selectDimeBasecombById(id));
    }

    /**
     * 新增项目组合管理
     */
    @RequiresPermissions("basic:basecomb:add")
    @Log(title = "项目组合管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DimeBasecomb dimeBasecomb)
    {
        return toAjax(dimeBasecombService.insertDimeBasecomb(dimeBasecomb));
    }

    /**
     * 修改项目组合管理
     */
    @RequiresPermissions("basic:basecomb:edit")
    @Log(title = "项目组合管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DimeBasecomb dimeBasecomb)
    {
        return toAjax(dimeBasecombService.updateDimeBasecomb(dimeBasecomb));
    }

    /**
     * 删除项目组合管理
     */
    @RequiresPermissions("basic:basecomb:remove")
    @Log(title = "项目组合管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(dimeBasecombService.deleteDimeBasecombByIds(ids));
    }

    /**
     * 接口获取项目
     * @param combo
     * @return
     */
    @InnerAuth
    @PostMapping("/info/combos")
    public R<List<ComboBase>> allCombos(@RequestBody Combo combo)
    {

        List<ComboBase> list = dimeBasecombService.selectCombos(combo);
        return R.ok(list);
    }

    /**
     * 接口获取项目
     * @param combCode
     * @return
     */
    @InnerAuth
    @GetMapping("/info/combo/{combCode}")
    public R<ComboBase> combo(@PathVariable String combCode)
    {

        Combo combo = dimeBasecombService.selectCombo(combCode);
        return R.ok(combo);
    }

    /**
     * 接口获取项目
     * @param combCodes
     * @return
     */
    @InnerAuth
    @GetMapping("/info/combos/{combCodes}")
    public R<List<ComboBase>> combosbycodes(@PathVariable String combCodes)
    {
        String[] codes = combCodes.split(",");
        List<ComboBase> list = dimeBasecombService.selectCombosByCombCodes(codes);
        return R.ok(list);
    }

    @InnerAuth
    @PostMapping("/info/checkcombos")
    public R<DimeBasicDataResult> combo(@RequestBody List<ComboBase> combos)
    {
        DimeBasicDataResult list = dimeBasecombService.checkCombosAndItems(combos);
        return R.ok(list);
    }

    @InnerAuth
    @GetMapping("/info/harms/combos/{harmids}")
    public R<List<HarmCombo>> getComboByHarmIds(@PathVariable String[] harmids)
    {

        List<HarmCombo> list = dimeBasecombService.selectHarmCombosByHarmIds(harmids);
        return R.ok(list);
    }

    @GetMapping("/info/comboBase/{ids}")
    public R<List<DimeBasecomb>> getComboByIds(@PathVariable String[] ids)
    {

        List<DimeBasecomb> list = dimeBasecombService.selectCombosByIds(ids);
        return R.ok(list);
    }
}
